package com.zichen.pr.demo.student.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zichen.pr.common.constant.UserConstants;
import com.zichen.pr.common.exception.CustomException;
import com.zichen.pr.demo.student.entity.Student;
import com.zichen.pr.demo.student.mapper.StudentMapper;
import com.zichen.pr.system.entity.SysPost;
import com.zichen.pr.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: zichen
 * @description: 测试学生服务层
 * @author: rzhang
 * @create: 2021-04-26 08:27
 */
@Service
public class StudentService extends ServiceImpl<StudentMapper, Student> {

    @Resource
    private StudentMapper studentMapper;

    /**
     * 查询学生测试信息集合
     *
     * @param student 学生测试信息
     * @return 学生测试信息集合
     */
    public List<Student> selectStudentList(Student student) {
        return studentMapper.selectStudentList(student);
    }


    /**
     * 批量删除学生测试信息
     *
     * @param ids 需要删除的学生测试ID
     * @return 结果
     * @throws Exception 异常
     */
    public int deleteStudentByIds(Long[] ids) {
        return studentMapper.deleteStudentByIds(ids);
    }

    /**
     * 校验学生测试名称是否唯一
     *
     * @param student 学生测试信息
     * @return 结果
     */
    public String checkNameUnique(Student student) {
        Long u_id = StringUtils.isNull(student.getU_id()) ? -1L : student.getU_id();
        Student info = studentMapper.checkNameUnique(student.getU_name());
        if (StringUtils.isNotNull(info) && info.getU_id().longValue() != u_id.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
